class_name GameplayEffectModifierAsset
extends Resource

## 修改器的操作符
enum Operation {
	Override,
	Add,
	Multiply,
}

## 操作符
@export var operation: Operation

## 表达式
@export var expression: String


func get_magnitude(effect: GameplayEffect, source: Variant, target: Variant) -> float:
	var expression_cache = Expression.new()
	expression_cache.parse(expression, ["source", "target", "stack_count"])
	if expression_cache.has_execute_failed():
		Logger.fatal("Invalid modifier magnitude calculator expression with detailed error: %s." % expression_cache.get_error_text())
		return 0.0
	else:
		var stack_count: int = 0
		if effect.effect_asset.has_component("StackEffectComponent"):
			stack_count = effect.get_component("StackEffectComponent").stack_count

		return expression_cache.execute([
			AttributeAttributeProxy.new(source),
			AttributeAttributeProxy.new(target),
			stack_count
		])
